//unit tester template
//$Id: unit_tester.h 114 2009-08-29 17:52:39Z Oleg.Bulychov $
#pragma once

#if defined(BCALL)
    #error rename our macro :(
#endif
//________________________________________________________________________________________________________
#define BCALL(foo)\
{\
    bool r___ = (foo);\
    if (!r___)\
        return false;\
}

struct test_result
{
    enum ENUM_TEST_RESULT
    {
        TEST_FAILED,
        TEST_OK,
        TEST_DUMMY,
    };
    ENUM_TEST_RESULT res_;

    test_result(bool b): res_(b ? TEST_OK : TEST_FAILED)
    {}

    test_result(): res_(TEST_DUMMY)
    {}
};

template<int n>
struct test
{
    inline test_result run() 
    {
        return test_result();
    }
};

template<int n>
struct tester
{
    inline static bool run_Test()
    {
        BCALL(tester<n - 1>::run_Test());
        test_result r(test<n>().run());
        switch(r.res_)
        {
        case test_result::TEST_OK:
            std::cout << "Test " << n << " passed" << std::endl;
            return true;
        case test_result::TEST_DUMMY:
            return true;
        default:
            std::cout << "Test " << n << " failed :(" << std::endl;
            VERIFY_(0);
            return false;
        }
    }
};

template<>
struct tester<0>
{
    inline static bool run_Test() 
    {
        return true;
    }
};

/*usage

template<>
struct test<1>
{
    inline bool run()
    {
        return true;
    }
};

template<>
struct test<2>
{
    inline bool run()
    {
        return true;
    }
};

void Run_Tests()
{
    bool r = tester<16>().run_Test();
    if (r)
        std::cout << "All right" << std::endl;
}
*/


//EOF!
